﻿<template>
  <a-card :bordered="false">
    <div class="table-operator">
      <a-button v-if="hasPerm('rdrecords32.Add')" type="primary" icon="plus" @click="handleAdd()">新建</a-button>
      <a-button v-if="hasPerm('rdrecords32.Delete')" type="primary" icon="minus" @click="handleDelete(selectedRowKeys)"
        :disabled="!hasSelected()" :loading="loading">删除</a-button>
      <a-button type="primary" icon="redo" @click="getDataList()">刷新</a-button>
    </div>

    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="10">
          <a-col :md="4" :sm="24">
            <a-form-item label="查询类别">
              <a-select allowClear v-model="queryParam.condition">

                <a-select-option key="cBVencode">供应商编码</a-select-option>

              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="24">
            <a-form-item>
              <a-input v-model="queryParam.keyword" placeholder="关键字" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-button type="primary" @click="() => {
                this.pagination.current = 1
                this.getDataList()
              }
              ">查询</a-button>
            <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <a-table ref="table" :scroll="{ y: 530 }" :columns="columns" :rowKey="(row, index) => row.index" :dataSource="data"
      :pagination="pagination" :loading="loading" @change="handleTableChange"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" :bordered="true" size="small">
      <span slot="CreateTime" slot-scope="CreateTime">{{ timeFormat(CreateTime) }}</span>
      <span slot="action" slot-scope="text, record">
        <template>
          <a v-if="hasPerm('rdrecords32.Edit')" @click="handleEdit(record.Id)">编辑</a>
          <a-divider v-if="hasPerm('rdrecords32.Edit') && hasPerm('rdrecords32.Delete')" type="vertical" />
          <a v-if="hasPerm('rdrecords32.Delete')" @click="handleDelete([record.Id])">删除</a>
        </template>
      </span>
    </a-table>

    <edit-form ref="editForm" :parentObj="this"></edit-form>
  </a-card>
</template>

<script>
import EditForm from './EditForm'
import moment from 'moment'
const columns = [
  { title: '收发记录子表标识', dataIndex: 'AutoID', width: '10%' },
  { title: '收发记录主表标识', dataIndex: 'ID', width: '10%' },
  { title: '存货编码', dataIndex: 'cInvCode', width: '10%' },
  { title: '辅计量数量', dataIndex: 'iNum', width: '10%' },
  { title: '数量', dataIndex: 'iQuantity', width: '10%' },
  { title: '单价', dataIndex: 'iUnitCost', width: '10%' },
  { title: '金额', dataIndex: 'iPrice', width: '10%' },
  { title: '暂估金额', dataIndex: 'iAPrice', width: '10%' },
  { title: '计划价或售价', dataIndex: 'iPUnitCost', width: '10%' },
  { title: '计划金额或售价金额', dataIndex: 'iPPrice', width: '10%' },
  { title: '批号', dataIndex: 'cBatch', width: '10%' },
  { title: '对应入库单子表标识', dataIndex: 'cVouchCode', width: '10%' },
  { title: '对应入库单号', dataIndex: 'cInVouchCode', width: '10%' },
  { title: '入库单单类型', dataIndex: 'cinvouchtype', width: '10%' },
  { title: '累计出库数量', dataIndex: 'iSOutQuantity', width: '10%' },
  { title: '累计出库辅计量数量', dataIndex: 'iSOutNum', width: '10%' },
  { title: '出库单id', dataIndex: 'coutvouchid', width: '10%' },
  { title: '出库单类型', dataIndex: 'coutvouchtype', width: '10%' },
  { title: '累计退货数量', dataIndex: 'iSRedOutQuantity', width: '10%' },
  { title: '累计退货件数', dataIndex: 'iSRedOutNum', width: '10%' },
  { title: '存货自由项1', dataIndex: 'cFree1', width: '10%' },
  { title: '存货自由项2', dataIndex: 'cFree2', width: '10%' },
  { title: '标志', dataIndex: 'iFlag', width: '10%' },
  { title: '实际辅计量数量', dataIndex: 'iFNum', width: '10%' },
  { title: '实际数量', dataIndex: 'iFQuantity', width: '10%' },
  { title: '失效日期', dataIndex: 'dVDate', width: '10%' },
  { title: '货位编码', dataIndex: 'cPosition', width: '10%' },
  { title: '表体自定义项22', dataIndex: 'cDefine22', width: '10%' },
  { title: '表体自定义项23', dataIndex: 'cDefine23', width: '10%' },
  { title: '表体自定义项24', dataIndex: 'cDefine24', width: '10%' },
  { title: '表体自定义项25', dataIndex: 'cDefine25', width: '10%' },
  { title: '表体自定义项26', dataIndex: 'cDefine26', width: '10%' },
  { title: '表体自定义项27', dataIndex: 'cDefine27', width: '10%' },
  { title: '项目大类编码', dataIndex: 'cItem_class', width: '10%' },
  { title: '项目编码', dataIndex: 'cItemCode', width: '10%' },
  { title: '发货退货单子表标识', dataIndex: 'iDLsID', width: '10%' },
  { title: '发票子表标识', dataIndex: 'iSBsID', width: '10%' },
  { title: '本次发货数量', dataIndex: 'iSendQuantity', width: '10%' },
  { title: '本次发货辅计量数量', dataIndex: 'iSendNum', width: '10%' },
  { title: '委托代销发货单子表标识', dataIndex: 'iEnsID', width: '10%' },
  { title: '项目名称', dataIndex: 'cName', width: '10%' },
  { title: '项目大类名称', dataIndex: 'cItemCName', width: '10%' },
  { title: '存货自由项3', dataIndex: 'cFree3', width: '10%' },
  { title: '存货自由项4', dataIndex: 'cFree4', width: '10%' },
  { title: '存货自由项5', dataIndex: 'cFree5', width: '10%' },
  { title: '存货自由项6', dataIndex: 'cFree6', width: '10%' },
  { title: '存货自由项7', dataIndex: 'cFree7', width: '10%' },
  { title: '存货自由项8', dataIndex: 'cFree8', width: '10%' },
  { title: '存货自由项9', dataIndex: 'cFree9', width: '10%' },
  { title: '存货自由项10', dataIndex: 'cFree10', width: '10%' },
  { title: '对应条形码编码', dataIndex: 'cBarCode', width: '10%' },
  { title: '应收应发数量', dataIndex: 'iNQuantity', width: '10%' },
  { title: '应收应发辅计量数量', dataIndex: 'iNNum', width: '10%' },
  { title: '辅计量单位编码', dataIndex: 'cAssUnit', width: '10%' },
  { title: 'dMadeDate', dataIndex: 'dMadeDate', width: '10%' },
  { title: '保质期天数', dataIndex: 'iMassDate', width: '10%' },
  { title: '表体自定义项28', dataIndex: 'cDefine28', width: '10%' },
  { title: '表体自定义项29', dataIndex: 'cDefine29', width: '10%' },
  { title: '表体自定义项30', dataIndex: 'cDefine30', width: '10%' },
  { title: '表体自定义项31', dataIndex: 'cDefine31', width: '10%' },
  { title: '表体自定义项32', dataIndex: 'cDefine32', width: '10%' },
  { title: '表体自定义项33', dataIndex: 'cDefine33', width: '10%' },
  { title: '表体自定义项34', dataIndex: 'cDefine34', width: '10%' },
  { title: '表体自定义项35', dataIndex: 'cDefine35', width: '10%' },
  { title: '表体自定义项36', dataIndex: 'cDefine36', width: '10%' },
  { title: '表体自定义项37', dataIndex: 'cDefine37', width: '10%' },
  { title: '检验单子表标识', dataIndex: 'iCheckIds', width: '10%' },
  { title: '供应商编码', dataIndex: 'cBVencode', width: '10%' },
  { title: '是否质检', dataIndex: 'bGsp', width: '10%' },
  { title: '质检状态', dataIndex: 'cGspState', width: '10%' },
  { title: '检验单号', dataIndex: 'cCheckCode', width: '10%' },
  { title: '检验单子表ID', dataIndex: 'iCheckIdBaks', width: '10%' },
  { title: '不良品处理单号', dataIndex: 'cRejectCode', width: '10%' },
  { title: '不良品处理单ID', dataIndex: 'iRejectIds', width: '10%' },
  { title: '检验员', dataIndex: 'cCheckPersonCode', width: '10%' },
  { title: '检验日期', dataIndex: 'dCheckDate', width: '10%' },
  { title: '保质期单位', dataIndex: 'cMassUnit', width: '10%' },
  { title: '是否已经生成退货报检单1：生成,0:没有生成', dataIndex: 'iRefundInspectFlag', width: '10%' },
  { title: '合同标标识', dataIndex: 'strContractId', width: '10%' },
  { title: '合同号', dataIndex: 'strCode', width: '10%' },
  { title: '销售出库单是否报检', dataIndex: 'bChecked', width: '10%' },
  { title: '设备字表id', dataIndex: 'iEqDID', width: '10%' },
  { title: '预留升级问题', dataIndex: 'bLPUseFree', width: '10%' },
  { title: '行号', dataIndex: 'iRSRowNO', width: '10%' },
  { title: 'ioritrackid', dataIndex: 'iOriTrackID', width: '10%' },
  { title: '原始入库单类型', dataIndex: 'coritracktype', width: '10%' },
  { title: '表体记账人', dataIndex: 'cbaccounter', width: '10%' },
  { title: '表体记账日期', dataIndex: 'dbKeepDate', width: '10%' },
  { title: '单据是否核算', dataIndex: 'bCosting', width: '10%' },
  { title: '代管消耗标识', dataIndex: 'bVMIUsed', width: '10%' },
  { title: '代管结算数量', dataIndex: 'iVMISettleQuantity', width: '10%' },
  { title: '代管结算件数', dataIndex: 'iVMISettleNum', width: '10%' },
  { title: '代管商编码', dataIndex: 'cvmivencode', width: '10%' },
  { title: '序列号数量', dataIndex: 'iInvSNCount', width: '10%' },
  { title: '库管员编码', dataIndex: 'cwhpersoncode', width: '10%' },
  { title: '库管员名称', dataIndex: 'cwhpersonname', width: '10%' },
  { title: '服务单据id', dataIndex: 'cserviceoid', width: '10%' },
  { title: '服务单id', dataIndex: 'cbserviceoid', width: '10%' },
  { title: '换算率', dataIndex: 'iinvexchrate', width: '10%' },
  { title: '发货单号', dataIndex: 'cbdlcode', width: '10%' },
  { title: 'corufts', dataIndex: 'corufts', width: '10%' },
  { title: '合同GUID', dataIndex: 'strContractGUID', width: '10%' },
  { title: '有效期推算方式', dataIndex: 'iExpiratDateCalcu', width: '10%' },
  { title: '有效期至', dataIndex: 'cExpirationdate', width: '10%' },
  { title: '有效期计算项', dataIndex: 'dExpirationdate', width: '10%' },
  { title: '手册号', dataIndex: 'cciqbookcode', width: '10%' },
  { title: '累计保税处理抽取数量', dataIndex: 'iBondedSumQty', width: '10%' },
  { title: '库户存货编码', dataIndex: 'ccusinvcode', width: '10%' },
  { title: '客户存货名称', dataIndex: 'ccusinvname', width: '10%' },
  { title: '订单子表id', dataIndex: 'iorderdid', width: '10%' },
  { title: '订单类型', dataIndex: 'iordertype', width: '10%' },
  { title: '订单号', dataIndex: 'iordercode', width: '10%' },
  { title: '销售订单行号', dataIndex: 'iorderseq', width: '10%' },
  { title: 'pe需求id', dataIndex: 'ipesodid', width: '10%' },
  { title: 'pe需求类型', dataIndex: 'ipesotype', width: '10%' },
  { title: 'pe件需求跟踪号', dataIndex: 'cpesocode', width: '10%' },
  { title: 'pe需求行号', dataIndex: 'ipesoseq', width: '10%' },
  { title: '销售订单子表ID', dataIndex: 'isodid', width: '10%' },
  { title: '订单类型', dataIndex: 'isotype', width: '10%' },
  { title: '销售订单号', dataIndex: 'csocode', width: '10%' },
  { title: '销售订单行号', dataIndex: 'isoseq', width: '10%' },
  { title: '属性1', dataIndex: 'cBatchProperty1', width: '10%' },
  { title: '属性2', dataIndex: 'cBatchProperty2', width: '10%' },
  { title: '属性3', dataIndex: 'cBatchProperty3', width: '10%' },
  { title: '属性4', dataIndex: 'cBatchProperty4', width: '10%' },
  { title: '属性5', dataIndex: 'cBatchProperty5', width: '10%' },
  { title: '属性6', dataIndex: 'cBatchProperty6', width: '10%' },
  { title: '属性7', dataIndex: 'cBatchProperty7', width: '10%' },
  { title: '属性8', dataIndex: 'cBatchProperty8', width: '10%' },
  { title: '属性9', dataIndex: 'cBatchProperty9', width: '10%' },
  { title: '属性10', dataIndex: 'cBatchProperty10', width: '10%' },
  { title: '表体备注', dataIndex: 'cbMemo', width: '10%' },
  { title: '单据体行号', dataIndex: 'irowno', width: '10%' },
  { title: '行唯一ID', dataIndex: 'strowguid', width: '10%' },
  { title: '行时间戳', dataIndex: 'rowufts', width: '10%' },
  { title: '卸载前消抵数量', dataIndex: 'ipreuseqty', width: '10%' },
  { title: '卸载前消抵件数', dataIndex: 'ipreuseinum', width: '10%' },
  { title: '借出还回单子表id', dataIndex: 'iDebitIDs', width: '10%' },
  { title: '已开票数量', dataIndex: 'fsettleqty', width: '10%' },
  { title: '未开票退货数量', dataIndex: 'fretqtywkp', width: '10%' },
  { title: '已开票退货数量', dataIndex: 'fretqtyykp', width: '10%' },
  { title: '单据行条码', dataIndex: 'cbsysbarcode', width: '10%' },
  { title: '是否存货核算开票', dataIndex: 'bIAcreatebill', width: '10%' },
  { title: '是否销售出库开票', dataIndex: 'bsaleoutcreatebill', width: '10%' },
  { title: '出库单子表标识', dataIndex: 'isaleoutid', width: '10%' },
  { title: '是否需要开票', dataIndex: 'bneedbill', width: '10%' },
  { title: '是否指定货位', dataIndex: 'iposflag', width: '10%' },
  { title: '无', dataIndex: 'body_outid', width: '10%' },
  {
    title: '创建时间',
    dataIndex: 'CreateTime',
    width: '10%',
    align: 'center',
    scopedSlots: { customRender: 'CreateTime' }
  },
  { title: '操作', dataIndex: 'action', align: 'left', scopedSlots: { customRender: 'action' } }
]

export default {
  components: {
    EditForm
  },
  mounted() {
    this.getDataList()
  },
  data() {
    return {
      data: [],
      pagination: {
        current: 1,
        pageSize: 25,
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
        pageSizeOptions: ['25', '50', '100'], // 设置pageSize的可选值，页面可以通过下拉框进行选择
        showSizeChanger: true
      },
      filters: {},
      sorter: { field: 'Id', order: 'desc' },
      loading: false,
      columns,
      queryParam: {},
      selectedRowKeys: []
    }
  },
  methods: {
    handleTableChange(pagination, filters, sorter) {
      this.pagination = { ...pagination }
      this.filters = { ...filters }

      this.getDataList()
    },
    getDataList() {
      this.selectedRowKeys = []

      this.loading = true
      this.$http
        .post('/OrderManagement/rdrecords32/GetDataList', {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: this.sorter.field || 'Id',
          SortType: this.sorter.order,
          DeptId: this.DeptId,
          Search: this.queryParam,
          ...this.filters
        })
        .then(resJson => {
          this.loading = false
          this.data = resJson.Data
          if (this.data) {
            const pagination = { ...this.pagination }
            pagination.total = resJson.Total
            this.pagination = pagination
          }
        })
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    hasSelected() {
      return this.selectedRowKeys.length > 0
    },
    handleAdd() {
      this.$refs.editForm.openForm(null, '新建销售出库单子表信息')
    },
    handleEdit(id) {
      this.$refs.editForm.openForm(id, '编辑销售出库单子表信息')
    },
    handleDelete(ids) {
      var thisObj = this
      // this.$confirm({
      //   title: '确认删除吗?',
      //   onOk() {
      //     return new Promise((resolve, reject) => {
      //       thisObj.$http.post('/OrderManagement/rdrecords32/DeleteData', ids).then(resJson => {
      //         resolve()

      //         if (resJson.Success) {
      //           thisObj.$message.success('操作成功!')

      //           thisObj.getDataList()
      //         } else {
      //           thisObj.$message.error(resJson.Msg)
      //         }
      //       })
      //     })
      //   }
      // })

      this.$confirm('确认删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        thisObj.$http
          .post('/OrderManagement/rdrecords32/DeleteData', ids)
          .then(resJson => {
            // resolve()

            if (resJson.Success) {
              thisObj.$message.success('操作成功!')

              thisObj.getDataList()
            } else {
              thisObj.$message.error(resJson.Msg)
            }
          })
      })
    },
    timeFormat(val) {
      // 时间格式化函数
      return moment(val).format('YYYY-MM-DD HH:mm')
    }
  }
}
</script>
